import 'package:flutter/material.dart';

class Product{
  final String title; /// 商品标题
  final String description; /// 商品描述
  Product(this.title, this.description);
}

class ProductList extends StatelessWidget {
  final List<Product> products;
  ProductList({Key key, this.products}):super(key:key);
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text('商品列表')
        ),
        body: ListView.builder(
          itemCount: products.length,
          itemBuilder: (context, index){
            return ListTile(
              title: Text(products[index].title),
              onTap: (){
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => new ProductDetail(
                      product: products[index],
                    )
                  )
                );
              }
            );
          }
        )
      )
    );
  }
}

class ProductDetail extends StatelessWidget {
  final Product product;
  ProductDetail({Key key, @required this.product}):super(key:key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          title: Text('${product.title}'),
        ),
        body: Center(
          child: Text('${product.description}'),
        )
      )
    );
  }
}
